package com.alibaba.citrus.ots.application.report.ability.facade.config;

import com.alibaba.cz.es.helper.ElasticSearchClientFactory;
import com.alibaba.cz.es.properties.ElasticSearchProperties;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

/**
 * @author myw
 * @date 2022/04/10
 *
 **********************************************************************
 ***沙盒本地调试请注释这个类文件，@Value("${es.host}")在沙盒环境启动不生效*****
 * ********************************************************************
 */

@Component
public class ESRestHighLevelClient {

    @Value("${es.host}")
    private String ES_HOST;

    private Integer ES_PORT=9200;

    @Value("${es.username}")
    private String ES_USERNAME;

    @Value("${es.password}")
    private String ES_PASSWORD;

    @Bean(name = "restHighLevelClient")
    public RestHighLevelClient restHighLevelClient() {
        ElasticSearchProperties elasticSearchProperties = new ElasticSearchProperties();

        elasticSearchProperties.setHost(ES_HOST);
        elasticSearchProperties.setPort(ES_PORT);
        elasticSearchProperties.setUsername(ES_USERNAME);
        elasticSearchProperties.setPassword(ES_PASSWORD);
//        elasticSearchProperties.setHost("es-cn-s80lt45n6i5b45s9z.public.elasticsearch.aliyuncs.com");
//        elasticSearchProperties.setPort(9200);
//        elasticSearchProperties.setUsername("elastic");
//        elasticSearchProperties.setPassword("QAZokm123");
        return ElasticSearchClientFactory.getClient(elasticSearchProperties);
    }

}
